﻿using System.Collections.Generic;
using Vra.DataAccess.Entities;
using Vra.DataAccess.Misc;

namespace Vra.DataAccess
{
	public class CustomerDao : CommonDao<Customer>, ICustomerDao
	{
		public IList<Customer> SearchCustomer(string name, string country, string city)
		{
			IList<Customer> customers = new List<Customer>();
			using (var conn = GetConnection())
			{
				conn.Open();

				using (var cmd = conn.CreateCommand())
				{
					cmd.CommandText = QueryManager.GetSelectQuery<Customer>() + " WHERE Name like '%'+@Name+'%' AND Country like '%'+@Country+'%' AND City like '%'+@City+'%'";
						//"SELECT CustomerID, Name, Email, AreaCode, PhoneNumber, Street, City, Region, ZipPostalCode, Country, HouseNumber FROM CUSTOMER WHERE Name like @Name AND Country like @Country AND City like @City";
					cmd.Parameters.AddWithValue("@Name", name);
					cmd.Parameters.AddWithValue("@Country", country);
					cmd.Parameters.AddWithValue("@City", city);
					using (var dataReader = cmd.ExecuteReader())
					{
						while (dataReader.Read())
						{
							customers.Add(LoadItem(dataReader));
						}
					}
				}
			}
			return customers;
		}
	}
}